<!DOCTYPE HTML>
<html>
<head>
<title>ComObjGet() | AutoHotkey</title>
<meta name="description" content="The ComObjGet function returns a reference to an object provided by a COM component." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>ComObjGet() <span class="ver">[AHK_L 53+]</span></h1>
<p>返回由 COM 组件提供的对象引用.</p>
<pre class="Syntax">ComObject := <span class="func">ComObjGet</span>(Name)</pre>

<h2 id="Parameters">参数</h2>
<dl>

  <dt>Name</dt>
  <dd><p>需要获取的对象的显示名称. 请参阅 <a href="http://msdn.microsoft.com/en-us/library/ms691253.aspx">MkParseDisplayName (MSDN)</a> 了解更多信息.</p></dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>失败时, 函数可能会抛出异常, 退出脚本或返回空字符串, 具体取决于当前的 <a href="ComObjError.htm">ComObjError()</a> 设置和<a href="ComObjError.htm#factors">其他因素</a>.</p>

<h2 id="Related">相关</h2>
<a href="ComObjCreate.htm">ComObjCreate()</a>, <a href="ComObjActive.htm">ComObjActive()</a>, <a href="ComObjConnect.htm">ComObjConnect()</a>, <a href="ComObjError.htm">ComObjError()</a>, <a href="ComObjQuery.htm">ComObjQuery()</a>, <a href="http://msdn.microsoft.com/en-us/library/ms678805.aspx">CoGetObject (MSDN)</a>

<h2 id="Examples">示例</h2>
<div class="ex" id="exwmi">
<p><a class="ex_number" href="#exwmi"></a> 按下 <kbd>Shift</kbd>+<kbd>Esc</kbd> 来显示活动窗口进程的命令行. 需要 XP 或更高版本.</p>
<pre>+Esc::
    WinGet pid, PID, A
    <em>; 获取 WMI 服务对象.</em>
    wmi := ComObjGet("winmgmts:")
    <em>; 执行查询以获取匹配进程.</em>
    queryEnum := wmi.ExecQuery(""
        . "Select * from Win32_Process where ProcessId=" . pid)
        ._NewEnum()
    <em>; 获取首个匹配进程.</em>
    if queryEnum[proc]
        MsgBox 0, Command line, % proc.CommandLine
    else
        MsgBox Process not found!
      <em>; 释放所有全局对象(使用局部变量时不需要这么做).</em>
    wmi := queryEnum := proc := ""
return
<em>; Win32_Process: <a href="http://msdn.microsoft.com/en-us/library/aa394372.aspx">http://msdn.microsoft.com/en-us/library/aa394372.aspx</a></em>
</pre>
</div>

</body>
</html>